package com.xiguaji.tiktok.v1.common.controller;

import com.xiguaji.tiktok.config.exception.ParamsException;
import com.xiguaji.tiktok.utils.Ret;
import com.xiguaji.tiktok.v1.BaseController;
import com.xiguaji.tiktok.v1.common.service.CommonService;
import com.xiguaji.tiktok.v1.user.log.Operation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@RestController
@Api(value = "公共",tags = {"公共"})
public class CommonController extends BaseController {

    @Autowired
    CommonService commonService;

    @ApiOperation(value = "获取国家列表")
    @RequestMapping(value = "common/region",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
    @Operation(value = "获取国家列表")
    public String getRegionList(String data) throws UnsupportedEncodingException, ParamsException {
        if(StringUtils.isEmpty(data)){
            return Ret.success("success",commonService.allRegions);
        }
        Integer type = getParam(Integer.class, URLDecoder.decode(data,"UTF-8"),"type");
        return Ret.success("success",commonService.getRegion(type));
    }

    @ApiOperation(value = "获取语言列表")
    @RequestMapping(value = "common/language",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
    @Operation(value = "获取语言列表")
    public String getLanguageList(String data) throws UnsupportedEncodingException, ParamsException {
        if(StringUtils.isEmpty(data)){
            return Ret.success("success",commonService.allLanguages);
        }
        Integer type = getParam(Integer.class, URLDecoder.decode(data,"UTF-8"),"type");
        return Ret.success("success",commonService.getLanguage(type));
    }
}
